﻿''=================================
'' file:ImageControl.vb
'' desc:图像控件
'' date:
'' author:
'' version: 1.0
''
'' History
''  version:1.0
''  author: lidalong
''  date:   2010-04-22
''  desc:   计算控件对应的字体
''===============================

Imports System.Drawing

''' <summary>
''' 控件字体大小计算辅助类
''' </summary>
''' <remarks></remarks>
Public Class FontCalculateHelper
    ''' <summary>
    ''' 通过字体高度返回适当的字体
    ''' </summary>
    ''' <param name="ctlHight">字体高度</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Friend Shared Function AdjustFont(ByVal ctlHight As Integer) As Font
        Dim font As Font
        Dim Size As Integer = 9
        Select Case (ctlHight)
            Case 1 To 10
                Size = 6
            Case 11
                Size = 8
            Case 12, 13
                Size = 9
            Case 14
                Size = 10
            Case 15
                Size = 11
            Case 16, 17
                Size = 12
            Case 18, 19
                Size = 14
            Case 20, 21
                Size = 15
            Case 22, 23
                Size = 16
            Case 24, 25
                Size = 16
            Case 24 To 26
                Size = 18
            Case 27 To 29
                Size = 20
            Case 30 To 32
                Size = 22
            Case 33, 34
                Size = 24
            Case 35 To 37
                Size = 26
            Case 38 To 47
                Size = 28
            Case 48 To 55
                Size = 36
            Case 56 To 64
                Size = 42
            Case Else
                Size = 48
        End Select
        font = New Font("宋体", Size)
        Return font
    End Function

    ''' <summary>
    ''' 获取字符串中文字字数
    ''' </summary>
    ''' <param name="str"></param>
    ''' <returns></returns>
    ''' <remarks>对于一个中文则为2个字符</remarks>
    Friend Shared Function CharactersCount(ByVal str As String)
        Return System.Text.Encoding.Default.GetByteCount(str)
    End Function
End Class
